<template>
  <el-dialog v-model="visible" title="修改vip等级" :close-on-click-modal="false">
    <el-form
      ref="dataFormRef"
      :model="dataForm"
      :rules="dataRule"
      label-width="120px"
      @keyup.enter="onSubmit()"
    >
      <el-form-item label="用户ID" prop="userId">
        <el-input v-model="dataForm.userId" :disabled="true" placeholder="用户ID" />
      </el-form-item>
      <el-form-item label="用户账号" prop="nickName">
        <el-input v-model="dataForm.nickName" :disabled="true" placeholder="用户账号" />
      </el-form-item>
      <el-form-item label="用户姓名" prop="realName">
        <el-input v-model="dataForm.realName" :disabled="true" placeholder="用户姓名" />
      </el-form-item>

      <el-form-item label="会员等级" prop="vipLevel">
        <el-radio-group v-model="dataForm.vipLevel">
          <el-radio :label="0">普通会员</el-radio>
          <el-radio :label="1">vip</el-radio>
          <el-radio :label="2">svip</el-radio>
          <el-radio :label="3">分部(销售团队)</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="onSubmit()">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
const emit = defineEmits(["refreshDataList"]);

const page = reactive({
  total: 0, // 总页数
  currentPage: 1, // 当前页数
  pageSize: 10, // 每页显示多少条
});

const dataForm = ref({
  userId: "",
  nickName: "",
  realName: "",

  vipLevel:""
});

const dataRule = {
  //vipLevel: [{ required: true, message: "选择推荐人不能为空", trigger: "blur" }],
};
const visible = ref(false);
const dataFormRef = ref(null);
const init = (row) => {
  visible.value = true;
  //dataForm.value = Object.assign({}, row) || {};
  dataForm.value = row || {};

  nextTick(() => {
    //在 el-form 中的字段,调用resetFields方法后会将当前值,覆盖为第一次打开el-form时各字段的值
    //dataFormRef.value?.resetFields();
  });
};
defineExpose({ init });



const onSubmit = Debounce(() => {
  dataFormRef.value?.validate((valid) => {
    if (valid) {
      http({
        url: http.adornUrl("/admin/user"),
        method: "put",
        data: http.adornData({
          userId: dataForm.value.userId || undefined,
          vipLevel: dataForm.value.vipLevel,
        }),
      }).then(() => {
        ElMessage({
          message: "操作成功",
          type: "success",
          duration: 1500,
          onClose: () => {
            visible.value = false;
            emit("refreshDataList", page);
          },
        });
      });
    }
  });
});





</script>

<style scoped lang="scss">

</style>

<style scoped>

</style>
